<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
*{
	padding:0px;
	margin:0px;
}
#container{
	margin:auto;
	width:900px;	
	font-family: Tahoma, Helvetica, sans-serif;
	font-size:13px;
}
#container #tableinfo{
	width:100%;
	border:0px solid #FFFFFF;
	text-align:center;	
	font-size:13px;
}

#tableinfo .info_le{
	background-color:#FFFFFF;
}
#tableinfo .info_chan{
	background-color:#99CCFF;
}
#title{
	font-weight:bold;
	color:#09C;
	background-color:#CCCCFF;
}

#tableinfo .left{
	text-align:left;
}
</style>
<body>
<title>Hóa đơn đặt hàng</title>
<div id="container">
<?
	
include_once("../common/config.php");
include_once("../common/init.php"); 
global $db;
include_once(DIR_MODEL."md_setting_web.class.php");
$objModelSettingWeb = new MD_SettingWeb($db);
$arrayDataSettingWeb = $objModelSettingWeb->getByWhere("*","");
//thong tin hoa don
$mahoadon = $_GET['mahoadon'];
$arrayData = array();
$sql = "SELECT * FROM ".DB_FIX."hoadon WHERE mahoadon = '".$mahoadon."'";
$result = mysql_query($sql);
$arrayData = mysql_fetch_array($result);

//chi tiet hoa don
$sql_Bill = "SELECT * FROM ".DB_FIX."chitiethoadon WHERE mahoadon = '".$mahoadon."'";
$result_Bill = mysql_query($sql_Bill);

//san pham
include_once(DIR_MODEL."md_san_pham.class.php");
$objModelSP = new MD_Sanpham($db);

?>
	<table width="900" cellpadding="0" cellspacing="0" style="line-height:18px; " id="tableinfo">
		<tr>
			<td style="text-align:center; font-weight:bold; font-size:18px; ">WEBSITE THƯƠNG MẠI ĐIỆN TỬ GLOBE</td>
		</tr>
		<tr>
			<td style="text-align:center;  font-size:15px; ">Địa chỉ: <?=$arrayDataSettingWeb[0]['vpgd']?></td>
	   </tr>
	   <tr>
	   		<td style="text-align:center;  font-size:15px; ">
				Điện thoại: <?=$arrayDataSettingWeb[0]['dien_thoai']?>
			</td>
	   </tr>
	</table>
	
	<table width="900" id="tableinfo" style="line-height:18px; ">
		<tr>
			<td  style="padding:15px; ">&nbsp;</td>
		</tr>
		<tr>
			<td width="78%" align="center" style="padding:10px 0px; ">
				<b><font size="+2">HÓA ĐƠN MUA HÀNG</font></b>
			</td>
		</tr>
		<tr>
			<td  style="padding:15px; ">&nbsp;</td>
		</tr>
		<tr>
			<td  style="padding:5px 0px; ">
				<table width="100%" cellpadding="3" cellspacing="0" style="line-height:18px; ">
					<tr>
						<td width="47%">
							<table width="100%" cellpadding="3" cellspacing="0" style="line-height:18px; font-size:14px;">
								<tr>
									<td width="28%" style="padding:5px 0px; ">Mã HD:</td>
									<td  style="padding:5px 0px; "><?=$arrayData['mahoadon']?></td>
								</tr>
								<tr>
									<td width="28%" valign="top" style="padding:5px 0px; ">
										Ngày đặt hàng:
									</td>
									<td width="72%" style="padding:5px 0px; "><?=date("d/m/Y H:m",$arrayData['ngaydathang'])?></td>
								</tr>
								<tr>
									<td width="28%" valign="top" style="padding:5px 0px; ">
										Ngày giao hàng:
									</td>
									<td width="72%" style="padding:5px 0px; "><?=$arrayData['ngaygiaohang']?></td>
								</tr>
							</table>
						</td>
						<td width="53%" valign="top">
							<table width="100%" cellpadding="3" cellspacing="0" style="line-height:18px; ">
								<tr>
									<td width="40%" style="padding:5px 0px; ">
										Phương thức thanh toán:
									</td>
									<td width="60%"><? if($arrayData['loaihinhthanhtoan'] == 1){ echo "Thanh toán qua Bảo Kim";}else{ echo "Trả sau";}?></td>
								</tr>
								<tr>
									<td width="40%" style="font-weight:bold; padding:5px 0px;">
										Trạng thái đơn hàng:
									</td>
									<td>
										<font color="#FF0000"><b><? if($arrayData['trangthaidonhang'] == 1){ echo "Đặt hàng";}else{ echo "Đã thanh toán";}?></b></font>
									</td>
								</tr>
								<tr>
									<td>&nbsp;</td>
									<td>&nbsp;</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td  style="line-height:18px; ">
				<table width="100%" cellpadding="3" cellspacing="0" style="line-height:18px; ">
					<tr>
						<td width="47%">
							<table width="100%" cellpadding="5" cellspacing="0">
								<tr>
									<td colspan="2" valign="top" align="center" style="font-weight:bold; line-height:18px; padding:10px 0px;  ">
										Thông tin người mua
									</td>
								</tr>
								<tr>
									<td width="21%" style="line-height:18px; padding:5px 0px;">
										Họ và tên:
									</td>
									<td width="79%" style="line-height:18px; padding:5px 0px;">
										<?=$arrayData['tenkhachhang']?>
									</td>
								</tr>
								<tr>
									<td style="line-height:18px; padding:5px 0px;">Địa chỉ:</td>
									<td style="line-height:18px; padding:5px 0px;">
										<?=$arrayData['diachi']?>
									</td>
								</tr>
								<tr>
									<td style="line-height:18px; padding:5px 0px;">Điện thoại:</td>
									<td style="line-height:18px; padding:5px 0px;">
										<?=$arrayData['dienthoai']?>
									</td>
								</tr>
							</table>
						</td>
						<td width="53%" style="line-height:18px; ">
							<table width="100%" cellpadding="5" cellspacing="0">
								<tr>
									<td colspan="2" valign="top" align="center" style="font-weight:bold; line-height:18px; padding:10px 0px;">
										Thông tin người nhận
									</td>
								</tr>
								<tr>
									<td width="21%" style="line-height:18px; padding:5px 0px;">
										Họ và tên:
									</td>
									<td width="79%" style="line-height:18px; padding:5px 0px;">
										<?=$arrayData['tennguoinhan']?>
									</td>
								</tr>
								<tr>
									<td style="line-height:18px; padding:5px 0px;">Địa chỉ:</td>
									<td style="line-height:18px; padding:5px 0px;">
										<?=$arrayData['diachinhan']?>
									</td>
								</tr>
								<tr>
									<td style="line-height:18px; padding:5px 0px;">Điện thoại:</td>
									<td style="line-height:18px; padding:5px 0px;">
										<?=$arrayData['dienthoainhan']?>
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td style="line-height:18px; padding:5px 0px;">
							<font color="#FF0000"><b>Ghi chú :</b><span style="padding-left:10px; "><?=sub_str($arrayData['ghichunhan'],8)?> <? if(count($arrayDataSP['ghichunhan'])>8){ echo "..."; }?></span></font>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	
	<table width="900" id="tableinfo" style="line-height:18px; " cellpadding="3" cellspacing="3">
		<tr>
		 <td colspan="6">&nbsp;</td>
		 <td width="116" style="line-height:18px; padding:5px 5px;">Đơn vị tính:VNĐ</td>
		</tr>
		<tr id="title" valign="top">
		<td width="37" style="padding:10px 5px; ">STT</td>
		<td width="164" style="padding:10px 5px; ">Mã/Tên hàng</td>
		<td width="165" style="padding:10px 5px; ">Đóng gói</td>
		<td width="104" style="padding:10px 5px; ">Giá bao gồm VAT</td>
		<td width="112" style="padding:10px 5px; ">Số lượng</td>
		<td width="134" style="padding:10px 5px; ">Người bán</td>
		<td style="padding:10px 5px; ">Thành tiền</td>
	    </tr>
	  <?
	  $stt_bill = 1;
	  $tong = 0;
	  while($row = mysql_fetch_array($result_Bill)){
		$arrayDataSP = $objModelSP -> getById($row['mahang']);
		$giasp = $arrayDataSP["gia_sp_km"]>0?$arrayDataSP["gia_sp_km"]:$arrayDataSP["gia_sp"];
		$tong = $tong + ($giasp*$row['soluong']);
	  ?>
	  <tr class=" <? if($stt_bill % 2 == 0){?> info_chan <? }else{?> info_le <? }?>">
		<td style="padding:10px 5px; "><?=$stt_bill?></td>
		<td style="padding:10px 5px; "><b><?=$arrayDataSP['ten_sp']?></b></td>
		<td style="padding:10px 5px; "><?=sub_str($arrayDataSP['dong_goi'],8)?> <? if(count($arrayDataSP['dong_goi'])>8){ echo "..."; }?></td>
		<td style="padding:10px 5px; "><?=to_money($giasp)?></td>
		<td style="padding:10px 5px; "><?=$row['soluong']?></td>
		<td style="padding:10px 5px; ">Mua trực tiếp</td>
		<td style="padding:10px 5px; "><?=to_money($giasp*$row['soluong'])?></td>
	  </tr>
	  <?
		$stt_bill ++;
	  }
	  ?>
	  
	  <tr>
		<td >&nbsp;</td>
		<td >&nbsp;</td>
		<td >&nbsp;</td>
		<td >&nbsp;</td>
		<td >&nbsp;</td>
		<td  style="font-weight:bold;color:#09C; padding:10px 5px;">Tổng tiền hàng</td>
		<td style="padding:10px 5px; "><?=to_money($tong)?></td>
	  </tr>
	  <tr>
		<td >&nbsp;</td>
		<td >&nbsp;</td>
		<td >&nbsp;</td>
		<td >&nbsp;</td>
		<td >&nbsp;</td>
		<td >&nbsp;</td>
		<td >&nbsp;</td>
	  </tr>
	  <tr>
		<td >&nbsp;</td>
		<td >&nbsp;</td>
		<td >&nbsp;</td>
		<td >&nbsp;</td>
		<td >&nbsp;</td>
		<td  style="font-weight:bold;color:#09C; padding:10px 5px;">Tổng tiền</td>
		<td style="padding:10px 5px; "><?=to_money($tong)?></td>
	  </tr>
	  <tr>
	  <td colspan="7" style="padding-top:40px; "><hr /></td>
	  </tr>
	  <tr>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td><input type="submit" name="button" id="button" value="Đóng cửa sổ này" onClick="window.close();" /></td>
		<td><input type="submit" name="button2" id="button2" value="In đơn hàng này" onClick="window.print();" /></td>
		<td>&nbsp;</td>
	  </tr>
	</table>
</div><!-- container -->
</body>